package multidimensional;

import java.awt.Color;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;

import perspectives.Property;
import perspectives.PropertyManager.SaveFile;
import data.Table;
import data.TableData;
import util.Points2DViewer;

public class PlanarProjectionViewer extends Points2DViewer {
	
	Embedder2D embedder = null;
	
	private Table table = null;
	
	public PlanarProjectionViewer(String name, TableData t)
	{
		super(name);
		
		table = t.getTable();
		embedder = new SpringEmbedder(t.getTable());
		
		this.setPointSize(25);
	}

	@Override
	public <T> void propertyUpdated(Property p, T newvalue) {
	}

	@Override
	protected String getPointLabel(int p) {
		return table.getRowName(p);
	}

	@Override
	protected int getNumberOfPoints() {
		return table.getRowCount();
	}

	@Override
	protected int getPointX(int p) {
		return (int)(embedder.getX(p)*400);
	}

	@Override
	protected int getPointY(int p) {
		return (int)(embedder.getY(p)*400);
	}

	@Override
	protected void setPointX(int p, int x) {
		// TODO Auto-generated method stub
		embedder.setX(p, x/400.);
		
	}

	@Override
	protected void setPointY(int p, int y) {
		embedder.setY(p, y/400.);
		
	}

	@Override
	public void simulate() {
		if (embedder != null)
			embedder.iteration();
		
	}
}
